import { Injectable, ComponentFactoryResolver, Injector, ApplicationRef, Type } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class MuuriComponentService {
  constructor(
    private resolver: ComponentFactoryResolver,
    private injector: Injector,
    private app: ApplicationRef
  ) { }

  renderComponentToDom(dom: HTMLElement, component: Type<any>) {
    if (!component) {
      throw new Error('未找到对应的组件');
    }
    const factory = this.resolver.resolveComponentFactory(component);
    const ref = factory.create(this.injector, [], dom);
    this.app.attachView(ref.hostView);
    return ref;
  }

}

interface DataModelChange {
  bindField: string;
  value: any;
  identifyId: string;
}
